#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp> // 例如使用String消息类型，根据需要选择合适的消息类型
 
class MinimalSubscriber : public rclcpp::Node {
public:
  MinimalSubscriber() : Node("minimal_subscriber") {
    subscription_ = this->create_subscription<std_msgs::msg::String>(
      "topicName",  // 替换为你要订阅的话题名
      10,              // QoS设置，缓冲区大小10
      std::bind(&MinimalSubscriber::topic_callback, this, std::placeholders::_1)
    );
  }
 
private:
  void topic_callback(const std_msgs::msg::String::SharedPtr msg) const {
    RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str());
  }
  rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;
};
 
int main(int argc, char * argv[]) {
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<MinimalSubscriber>());
  rclcpp::shutdown();
  return 0;
}